package com.myjob.controller;

import com.myjob.entity.*;
import com.myjob.response.Result;
import com.myjob.service.BaseInfoService;
import com.myjob.service.ProfileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author chenyuan
 * @date 2020/12/30 20:11
 */
@RestController
@Slf4j
@RequestMapping("/account")
public class ProfileController {
	@Autowired
	private ProfileService profileService;
	@Autowired
	private BaseInfoService baseInfoService;

	@GetMapping("/profile")
	public Result selectProfileByUserId(@RequestParam("userId") String userId){
		Result result = null;

		try {
			result = profileService.selectProfileByUserId(userId);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}

	/** 教育经历 */
	@PostMapping("/education")
	public Result updateEducationById(@RequestBody Education education){
		Result result = null;

		try {
			result = profileService.updateEducationById(education);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}
	@DeleteMapping("/education")
	public Result deleteEducationById(@RequestBody Education education){
		Result result = null;

		try {
			result = profileService.deleteEducationById(education.getEducationId());
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}
	@PutMapping("/education")
	public Result addEducation(@RequestBody Education education){
		Result result = null;

		try {
			result = profileService.addEducation(education);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}

	/** 项目经验 */
	@PostMapping("/project")
	public Result updateProjectById(@RequestBody Project project){
		Result result = null;

		try {
			result = profileService.updateProjectById(project);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}
	@DeleteMapping("/project")
	public Result deleteProjectById(@RequestBody Project project){
		Result result = null;

		try {
			result = profileService.deleteProjectById(project.getProjectId());
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}
	@PutMapping("/project")
	public Result addProject(@RequestBody Project project){
		Result result = null;

		try {
			result = profileService.addProject(project);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}

	/** 技能信息 */
	@PostMapping("/skill")
	public Result updateSkillById(@RequestBody Skill skill) {
		Result result = null;

		try {
			result = profileService.updateSkillById(skill);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}
	@DeleteMapping("/skill")
	public Result deleteSkillById(@RequestBody Skill skill) {
		Result result = null;

		try {
			result = profileService.deleteSkillById(skill.getSkillId());
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}
	@PutMapping("/skill")
	public Result addSkill(@RequestBody Skill skill) {
		Result result = null;

		try {
			result = profileService.addSkill(skill);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}

	/** 个人网站 */
	@PostMapping("/website")
	public Result updateWebsiteById(@RequestBody Website website) {
		Result result = null;

		try {
			result = profileService.updateWebsiteById(website);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}
	@DeleteMapping("/website")
	public Result deleteWebsiteById(@RequestBody Website website) {
		Result result = null;

		try {
			result = profileService.deleteWebsiteById(website.getWebsiteId());
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}
	@PutMapping("/website")
	public Result addWebsite(@RequestBody Website website) {
		Result result = null;

		try {
			result = profileService.addWebsite(website);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}

	/** 工作经验 */
	@PostMapping("/work")
	public Result updateWorkById(@RequestBody Work work) {
		Result result = null;

		try {
			result = profileService.updateWorkById(work);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}
	@DeleteMapping("/work")
	public Result deleteWorkById(@RequestBody Work work) {
		Result result = null;

		try {
			result = profileService.deleteWorkById(work.getWorkId());
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}
	@PutMapping("/work")
	public Result addWork(@RequestBody Work work) {
		Result result = null;

		try {
			result = profileService.addWork(work);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return result;
	}
}
